Support include-prelude in smithy ast#2500
Support include-prelude in smithy ast#2500kstich merged 1 commit intosmithy-lang:mainfrom mullermp:ast-prelude
Conversation
Can you please elaborate on why is this needed? What use case are you trying to solve that needs the prelude shapes in the serialized model? |
|
Regardless of other implementations, I think being able to see the prelude shapes in the output of AST is useful, especially if those implementations need to see those definitions, or if you want a complete closure of the model to generate against. The closure I think is important so that implementations don't need to know about preludes at all. When I'm given a model, I expect that model to be complete. I otherwise need to special case every prelude ID. For example, if a structure targets a string, I can't visit that string, I need to inspect all keys of the structure and ignore prelude keys. If the string prelude is in the model, then I can iterate all members agnostically and check their type field, and visit shapes that way. |
yasmewad
left a comment
There was a problem hiding this comment.
Can you add unit tests for the flag?
I don't feel like this is useful enough to justify this change, in particular because, as discussed offline, the prelude shapes need to be known ahead of time anyway. It's also possible to configure the build to include them without any need for this change, see here. |
|
How do you use a smithy-build.json with the AST command? |
In general you can use But it doesn't seem to work as expected, not sure why. |
|
Yes, I tried that originally. I also don't know why a build config file shouldn't influence the AST command, so I ended up opening this PR. If |
|
This discrepancy is because the However, your implementation should probably be providing its own prelude. Requiring every provided model to bring it along is bound to create conflicts when a minor part of it changes (new or updated traits, etc.) and two models with different preludes are brought together. |
|
Thanks for the input. What do you mean? I thought this implementation just uses the same prelude that the other transforms rely on. If you have something different in mind, please take over the PR. |
|
Apologies, should have been clearer - that second paragraph is directed at this from the PR description:
|
|
I see. Yes, in Smithy Ruby, I have my own "prelude" hacked into the generator - where if a prelude shape such as This PR should probably include a test if you don't have one already. Thanks for looking into this. |
Background
It allows you to get prelude shapes when getting the AST.
Implementations that do not use Smithy in Java will need a way to get prelude shapes in the JSON model. Otherwise, special casing is necessary to handle prelude shapes.
Testing
clean,build, thensmithy-cli:runtime.smithy-cli/build/image/smithy-cli-darwin-aarch64/bin/smithy ast --include-preludewill include prelude shapes.By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.